<?php


namespace apps\marriage\app\op\controller;

use apps\marriage\core\service\ActivityMemberService;
use apps\marriage\core\service\ActivityService;
use apps\marriage\core\service\UserService;
use think\Request;

class ActivityApplyController extends BaseMarriageOpController
{
    /**
     * @var ActivityService
     */
    private $activityService;

    /**
     * @var ActivityMemberService
     */
    private $activityMemberService;

    /**
     * @var UserService
     */
    private $userService;

    protected function init()
    {
        parent::init();
        $this->activityService = service('Activity', SERVICE_NAMESPACE);
        $this->activityMemberService = service('ActivityMember', SERVICE_NAMESPACE);
        $this->userService = service('User', SERVICE_NAMESPACE);
    }

    public function lists(Request $request)
    {
        $activityId = $request->param('activity_id', 0, 'intval');
        $pageSize = $request->param('page_size', 10);
        $params = [
            'activity_id' => $activityId
        ];
        $res = $this->activityMemberService->pageListByParams($params, $pageSize);
        if($res['data']) {
            foreach ($res['data'] as &$rs) {
                $rs['user'] = $this->userService->getByPk($rs['user_id']);
            }
        }
        return $this->success($res);
    }
}